﻿using MiniExcelLibs;
using MiniExcelLibs.Attributes;

namespace _模拟题库上传数据解析
{
    internal class Program
    {
        static void Main(string[] args)
        {
            using (var stream = File.OpenRead(@"C:\\Users\\PC\\Desktop\\低压电工题库2.xlsx"))
            {
                var questionInputs = stream.Query<QuestionInput>().ToList();
                if (questionInputs is null || questionInputs.Count == 0)
                    return;
                List<QuestionOut> questionOuts = new List<QuestionOut>();
                for (int i = 0; i < questionInputs.Count; i++)
                {
                    QuestionOut questionOut = new QuestionOut();
                    switch (questionInputs[i].QuestionType)
                    {
                        case "判断题":
                            questionOut.QuestionType = 1;
                            break;
                        case "单选题":
                            questionOut.QuestionType = 2;
                            break;
                        case "多选题":
                            questionOut.QuestionType = 3;
                            break;
                    }
                    questionOut.Content = questionInputs[i].Content;
                    questionOut.Answer = questionInputs[i].Answer;
                    List<string> options = new List<string>();
                    options = questionInputs[i].Option.Split(';').ToList();
                    List<OptionsInfo> OptionsInfos = new List<OptionsInfo>();
                    for (int j = 0; j < options.Count; j++)
                    {
                        OptionsInfo optionsInfo = new OptionsInfo();
                        switch (j)
                        {
                            case 0:
                                optionsInfo.OptionTitle = "A";
                                break;
                            case 1:
                                optionsInfo.OptionTitle = "B";
                                break;
                            case 2:
                                optionsInfo.OptionTitle = "C";
                                break;
                            case 3:
                                optionsInfo.OptionTitle = "D";
                                break;
                            case 4:
                                optionsInfo.OptionTitle = "E";
                                break;
                            case 5:
                                optionsInfo.OptionTitle = "F";
                                break;
                            case 6:
                                optionsInfo.OptionTitle = "G";
                                break;
                        }
                        optionsInfo.OptionContent = options[j];
                        OptionsInfos.Add(optionsInfo);
                    }
                    questionOut.OptionsInfos = OptionsInfos;
                    questionOuts.Add(questionOut);
                }
            }

            //List<QuestionInput> questionInputs = new List<QuestionInput>();
            //QuestionInput questionInput = new QuestionInput()
            //{
            //    Number=1,
            //    QuestionType = "判断题",
            //    Content = "万能转换开关的定位结构一般采用滚轮卡转轴辐射型结构。",
            //    Answer = "B",
            //    Option = "正确;错误"
            //};
            //QuestionInput questionInput2 = new QuestionInput()
            //{
            //    Number = 2,
            //    QuestionType = "单选题",
            //    Content = "测量电动机线圈对地的绝缘电阻时,摇表的“L”、“E”两个接线柱应()。",
            //    Answer = "A",
            //    Option = "“L”接在电动机出线的端子,“E”接电动机的外壳;“E”接在电动机出线的端子,“L”接电动机的外壳;随便接,没有规定",
               
            //};
            //QuestionInput questionInput3 = new QuestionInput()
            //{Number = 1,
            //    QuestionType = "单选题",
            //    Content = "()的电机,在通电前,必须先做各绕组的绝缘电阻检查,合格后才可通电。",
            //    Answer = "C",
            //    Option = "一直在用,停止没超过一天;不常用,但电机刚停止不超过一天;新装或未用过的",
            //};
            //questionInputs.Add(questionInput);
            //questionInputs.Add(questionInput2);
            //questionInputs.Add(questionInput3);
           

        }
    }
    public class QuestionInput
    {
        [ExcelColumnName("序号")]
        public int? Number { get; set; }
        [ExcelColumnName("题型")]
        public string QuestionType { get; set; }
        [ExcelColumnName("题目内容")]
        public string Content { get; set; }
        [ExcelColumnName("可选项")]
        public string Option { get; set; }
        [ExcelColumnName("答案")]
        public string Answer { get; set; }

        [ExcelColumnName("报名日期")]
        public DateTime? Date { get; set; }
    }
    public class OptionsInfo
    {
        /// <summary>
        ///  A B C D
        /// </summary>
        public string OptionTitle { get; set; }
        /// <summary>
        /// 考试内容
        /// </summary>
        public string OptionContent { get; set; }

    }

    public class QuestionOut
    {
        public int QuestionType { get; set; }

        public string Content { get; set; }

        public List<OptionsInfo> OptionsInfos { get; set; }
        public string Answer { get; set; }
    }
}
